package com.factorit.spring;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SessionContext {

	/**
	 * Nombre del archivo de configuracion de Spring .
	 */
	private static String applicationContextFileName = "applicationContext.xml";

	private static ApplicationContext applicationContext = null;

	private SessionContext() {
		try {
			applicationContext = new ClassPathXmlApplicationContext(
					applicationContextFileName);
		} catch (Exception e) {
			e.printStackTrace(System.err);
		}
	}

	private static SessionContext instance = null;

	public static SessionContext getInstance() {
		if (instance == null) {
			instance = new SessionContext();
		}
		return instance;
	}

	public static SessionContext getInstance(String fileName) {
		SessionContext.applicationContextFileName = fileName;
		return SessionContext.getInstance();
	}

	public ApplicationContext getApplicationContext() {
		return applicationContext;
	}

	public Object getBean(String beanName) {
		return applicationContext.getBean(beanName);
	}

}
